package project5;

public class ErrorUtility
{
	/* Error messages. */
	public static final String ILL_FORMED_COMMAND = "ill-formed command";
	public static final String UNCAUGHT_EXCEPTION = "program terminated unexpectedly";	
	public static final String TOO_MANY_WORDS = "file contains too many words";
	public static final String CANNOT_FIND_FILE = "unable to process input file";
	public static final String CANNOT_READ_FILE = "unable to read input file";
	public static final String CANNOT_WRITE_FILE = "unable to write output file";
	public static final String ILL_RABID_COMMAND = "ill-formed RABID command";
	public static final String NON_OPERATOR = "the char is not an operator";
	public static final String ILL_QUERY_COMMAND = "ill-formed QUERY command";
	public static final String INAPPROPRIATE_REQUEST = "Inappropriate request";
	public static final String NON_EXIST_QUERY_OPERATOR = "Non-existing query operator";
	public static final String MODIFIED_SOURCE_FILE = "The files have been changed since the last build of the index file";
	public static final String NO_CORPUS_SPECIFIED = "Must supply a filename to build an index from.";
	
	public static void handleError(ProjectException e)
	{
/*		if(e.getMessage().equals(ILL_QUIRK_COMMAND)) {
			System.err.println("ERROR: " + e.getMessage());
		}
		else {
			System.err.println("ERROR: " + e.getMessage());
			System.exit(255);
		}*/
//		e.printStackTrace();
		handleMsg(e.getMessage());
	}
	
	public static void handleMsg(String msg)
	{
		if(msg.equals(ILL_RABID_COMMAND) 
				|| msg.equals(ILL_QUERY_COMMAND)
				|| msg.equals(INAPPROPRIATE_REQUEST)) {
			System.out.println(msg);
		}
		else {
			System.err.println("ERROR: " + msg);
			System.exit(255);
		}
	}
}
